<?php
function wechatLog($data)
{
	$file="wechatlog.txt";
	$ret = file_put_contents($file,$data,FILE_APPEND);
	
	//var_dump($file);exit();
	//// $content="signature:".$data['signature']."<br/>";
	//// $content=$content."echostr:".$data['echostr']."<br/>";
	//// $content=$content."timestamp:".$data['timestamp']."<br/>";
	//// $content=$content."nonce:".$data['nonce']."<br/>";
	//$content="hello";
	//var_dump($content);exit();
	//// $ret = file_put_contents($file,$content,FILE_APPEND);
	//var_dump($ret);exit();

}

function getAccessToken()
{
	// var_dump(cookie("access_token"));exit();
	if(cookie("access_token")!==NULL){
		$access_token= cookie("access_token");
	}else{
		$appID=C("appID");
		$appsecret=C("appsecret");
		$url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appID."&secret=".$appsecret;
		$ch = curl_init();  
		curl_setopt($ch,CURLOPT_URL,$url);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
		$output=curl_exec($ch);
		curl_close($ch);
		$output=json_decode($output);
		$access_token=$output->access_token;
		cookie("access_token",$access_token);
	}
	return $access_token;
	

}